package com.boot.boot2.service;

import com.boot.boot2.config.AutherProperties;
import com.boot.boot2.config.PersonProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

/**
 * Created by Wuxiang on 2018/5/8
 *
 * 读取 application.properties 文件中配置项
 * 1. 使用 @Value 注解  （优先读配置文件，没有读Java配置默认值）
 * 2. 利用 Environment 读取
 * 3. 利用 @ConfigurationProperties
 */
@Service
public class ConfigService {

    @Autowired
    PersonProperties personProperties;

    @Autowired
    Environment environment;

    @Autowired
    AutherProperties autherProperties;

    public String getPersonName() {
        return personProperties.getName();
    }

    public Integer getPersonAge() {
        return personProperties.getAge();
    }

    public String getPersonAddress(){
        return personProperties.getAddress();
    }

    public String getPersonSex() {
        return environment.getProperty("person.sex");
    }

    public String getAutherName() {
        return autherProperties.getName();
    }

    public Integer getAutherAge() {
        return autherProperties.getAge();
    }
}
